'Ritual', to me, implies some kind of magical thinking. You're doing it a certain way because it will have some kind of metaphysical effect. You curse someone, or you wear your lucky pants, or you avert some disaster, or you praise a god of some kind. You don't alter a ritual or it won't work. Worse, it may invite some proportionate disaster.
'Ceremony' would be a step down - you do things a certain way because it's a social, cultural or legal convention that you do. You may or may not have some latitude to change or improvise, but you know why you're doing what you do - it's most likely to do with some outside pressure, possibly quite mundane. You're getting married, or crowning the Queen, launching a ship or making tea, and it's important to you in whichever way that you do it correctly.
'Routine' would be another step down. You're doing things a certain way because it's comfortable, convenient or expedient for you. You drive a certain way to work, buy the same three sandwiches in rotation, attend the pub quiz on Mondays. You could alter a routine if you wanted, and the only real consequence would be that your life might become more irksome or less productive in some way. The act of altering the routine would not, in itself, bring you into disrepute, or break the law, etc.
A habit is something you do a certain way because you've inadvertently become programmed that way.