I agree with the other posters that what you (apparently) experienced is just normal business practice. Unfortunately, business relationships change the dynamics of "do unto others," and you need to just accept that. Just as you wouldn't go to your boss and say "I have an interview with this great other company, so plan that I may leave," so the company is not going to tell you they are planning to end their relationship with you.
That said, there are some things you can look out for that signal a genuine lack of ethics that could lead to more serious breaches of trust, like whether they would refuse to pay you for work already done.
I have found that when I am not comfortable with the business model of the company, usually there are deep ethical problems. For example, I once contracted for a company that, among other things, made corn dogs for schoolchildren to eat in cafeterias. That might not sound evil, and I ignored the feeling that there's something wrong about making money from putting something so unhealthy in front of children in an "official" setting.
Later, they had me working on a program that taught cafeterias to be more profitable by ensuring workers never got to full-time status and using plastic plates and utensils rather than washing more durable dishes. Again, not the soul of perfidy, but just a little ethically "icky." In the end, when they set an unrealistic deadline and I said it couldn't realistically be met, they refused to pay me for the previous month's work. The lesson here is to listen to your gut. If something doesn't feel right, look for another place to work ASAP.
The other part is how to spot if a layoff is coming and how to know if you are likely to be targeted.
If the business isn't doing well or is being acquired or merged with another company, layoffs are likely. If you, in particular, have a lot of idle time, you are likely to be laid off even if the business is otherwise normal.
If a general layoff is happening, you are likely to be targeted if you are not seen to "fit" well. Managers will "save" people that they perceive as more like them, so if you have a history of conflict, keep your head down and don't socialize, or are of a different ethnic group (or gender) than most managers, expect that you likely will be axed. The possible exception to this is if you bring in so much more money than you cost that they couldn't afford to lose you--and the decision-makers are aware of this.
The best protection is to never stop looking for a job. The problem is, this makes you exactly like the companies whose ethics you're not happy with. The next-best protection is to work hard to build your network and reputation, so that when you lose your job you are never far from the next one.