Common sense, laws, how I was raised.
Yes, it's perspective and context.
If you killed someone trying to harm your family are you a bad person? Religion says you should not kill, but you had to kill someone to save your wife/kid or would you let them die b/c you didn't want to kill someone? Religion labels you a bad person for any killing right? I would say good for you for protecting your family.
In my example, would you steal formula to feed your baby that you know is malnourished and will pass if they don't get food? Stealing is bad, but if you don't steal it leads to the death of your baby. Are you a bad person for stealing? I wouldn't fault you for stealing, religion would right?
Whether you already know or not, those common sense, laws, and how people are raised are all based on God's laws given to Israel long time ago. Many civilized societies have been practicing them ever since, the US being one of them since only couple hundered years ago. Those laws give distinction between things we consider good and bad. Killing, stealing, lying, etc. are considered bad so they've been prohibited and so forth. Before such laws were given, people were doing whatever seemed good to their own eyes. Sacrificing their own children to false gods and practicing homosexual activities to reach orgy for their idols were some of them. So God had to give Israel laws to bring orders forming a legitimate nation from the chaotic world. These are historical facts if you study history. So you're actually basing God's laws to consider a person including yourself good or bad.
I can't speak of other religions, but Christianity does not label all killing bad. In your example, that is a self-defense, a very thing we have as law in this country today as well. God also spoke of another killing when you "accidentally" kill someone, God commanded to have a place for them to run and hide at first to avoid any immediate retaliation before the judge brings justice. This is how we now have a court system. Of course an "intentional" killing is prohibited, but God does not label all killing bad as you mentioned. Also killing is a job to certain military people at war. God also told and ordered Israelite armies to kill those nations practicing baby sacrifices and nonsense thousands of years ago during wars. So these killing would not be counted as bad. Some people or religions today claim similar stuff and attack on certain groups and so forth, but God does not give such orders anymore today. God spoke everything we need to hear in the bible already. Anyone who says they're getting direct revelation from God now days is most likely a fraud or they're just acting out of their own will.
To answer your question on the baby formula, there are other ways you can do to avoid malnourishing your baby than stealing other's formula. Asking for help to your family, friends, or even the government are some ways you can try. But in absolute unavoidable situation, if you end up stealing, then you'll have to pay back later by the law unless you're forgiven and the debt is canceled. So is stealing in this situation considered bad? The bible or God's law does say yes just like this country's law does. Unlike killing, which is more complicated, stealing is strictly prohibited and you are not to practice it in any situation. But does that mean God will now punish you? This is where the gospel comes in.
God gave His laws to Israel and anyone who wanted to be in God's people were to practice them which results orderly nations. But the laws were not only to bring orders to His people. There was a bigger reason. We all know and God also knows following all these laws or rules is impossible for us. We might do a pretty good job and follow laws 90% of the time, but there will be moments where we just can't like the baby formula example you mentioned. Even without all these religious things, you'll still have to pay the penalty of whatever laws you break in this country even if you're a good person 90% of the time, right? So God wants to forgive us. He wants to cancel our debt 100%. So we're good 100% like God is good 100% thus we don't need to pay the penalty, even death penalty. But first, we have to admit we're short of keeping up the laws 100%. It doesn't matter if you're good 99.9%. There is only one 100%. That's why God sent His Son Jesus who is 100% good and He paid the price of our bad things by dying on the cross Himself. Even the better news is that He rose again from the dead so now whoever believes and have Jesus as the Lord will not only have our bad debts forgiven but will also have eternal life like Him. We are still to pay the penalty of laws we break in this world, but our falling short of God's perfect laws is taken care of by believing in Jesus.
Sorry for the long reply. You seemed to have questions on religions so I just did my best to answer and described as best as I could of what I believe. And all these are in the Holy Bible we all know. You said you don't believe you're a bad person. Maybe you really are a good person most of the time. Going to church or practicing any religious activities don't really make anyone a good person. So it is very possible your family and friends who attend church are not as good as you. Following God's laws not only on the outside but wholeheartedly makes one a good person, but we all know we can't follow 100%. While what we consider good and bad and also today's civilized laws are all based on God's laws initially, we just can't be 100% good to keep all of them. If we at least admit that and ask God for forgiveness of even that 0.1% of our bad, He will forgive us and give Jesus as our Lord, making our status 100% good. Those who don't admit and don't ask are just rejecting this good of a gift God offers.