The general rule of thumb: if you would feel bothered by the other person CCing your manager, don't do it to the other person. However, this general rule should be ignored when it's truly time to get someone in trouble for not doing their job, because you've already addressed it with that person without success, and you are putting the person on notice that you are escalating.
If you do want to escalate but don't want to send the extra message "and I want you to know I escalated because you're in trouble," consider sending the email without a CC, then afterward forward it to the escalation-handling authority.
Even if you are not escalating, it's good to be thoughtful about CCing managers. If you do have a concern about the recipient's reaction, the forwarding technique may be a good strategy in this case as well. Additionally, you can introduce the forwarded email with more information such as "oh hey, just wanted you to have an FYI because ... whatever ...".
This is less provocative than CCing directly, because if the person finds out you forwarded the email, you have a more plausible excuse–that you just neglected to CC the person at the time and you were merely trying to get work done. However, do be careful with this! Sometimes emails get forwarded, then again, then again, and the last person didn't read the whole thing carefully and sends it back to the person you didn't want to see it. So consider making your forwarding words bland, then have the controversial or sensitive part of the discussion with the boss or authority figure in person.
In my opinion, CCing someone's boss should normally only happen in these circumstances:
It's just a normal part of the business you have to do. The boss needs to know, or asked to be kept updated, or any other innocent and unsurprising reason that doesn't alarm or dismay anyone.
It's for escalation about a serious, unresolvable problem (as described above).
Aside from these, without a really good and clear reason why it's necessary, such a CC can be a threat with a pretty fine point on it. It can be passive aggressive, and manipulative, and petty, if done for the wrong reasons or before the right due diligence has been carried out. And this can rebound to your own harm.
If you want your boss or a person's boss to know something about a person, consider telling the superior separately. It's okay to include the person if that's what you have to do, but be aware that doing so is to pointedly communicate that one acceptable or even wanted outcome for you is that the person get into real trouble (not just for him to produce the work, but for him to be in trouble as an explicit, separate goal). That's not particularly good for building successful and supportive working relationships if done too lightly, or prematurely, now is it?
If you think a problem is worth sharing with someone's boss, see if you can first go to the person and talk about it. This is wise, and common courtesy besides, so do it unless there's a clear and objective rationale not to (perhaps you are afraid of retaliation or it's about bullying or harassment, perhaps). You never know if it was you who misunderstood something, and having that clear communication first can be the difference between you appearing to be the consummate professional on the one hand or looking like a jerk on the other.
The risks are even higher in the case of your own boss. More than with equal-rank coworkers, always seriously try to work things out with your boss before going over his/her head (again, unless a crime or other serious policy violation is occurring, and even then there is risk). Your boss is the last person whose goodwill you want to frivolously exhaust, because even if he/she doesn't become actually malicious, it's so easy for your boss to start failing to give you the benefit of the doubt, to start questioning your decisions, to stop trusting you, and so on—all things that will make your job harder and your success less likely.
Though, before you do anything at all about people not doing their jobs in a way that affects you, you might read the book Never Split the Difference: Negotiating As If Your Life Depended On It. Then you can use its techniques, such as an "accusation audit." You might say "have you given up on doing that work before the deadline?" Or a whole host of things that will help you negotiate with the person directly. Only after this fails should you escalate.
P.S. Going to someone's boss is a near-surefire way to make an enemy. Don't do it lightly, but do it calmly & confidently when you must. Objectively state what you observed, what you did, and what you need. Stay away from characterizations and subjective statements about the person. You can state your own subjective feelings, but that's because you are the only person who has any objective knowledge of your feelings and so this is a legitimate use of subjectivity, stating how a situation is (actually, objectively) affecting you.