수고하다 literally means "to make it hard for oneself," so keeping that in mind when you say it to someone in those situations you mentioned, the translations make a little sense and help you understand when to use it.
수고히십니다 - basic declarative sentence - You're working hard.
You greet someone who is working and you acknowledge that they are hard at work on something, hence "Hello."
수고하세요 - polite imperative - Please work hard.
As you leave, you are basically supporting them in their continued effort after you leave, hence "Goodbye"
수고하셨어요 - basic past tense - You worked hard.
You acknowledge that they either made an effort on your part and so you are thanking them, or you express admiration that they worked hard hence "Thank you" or "Well done!"
You can use them in pretty much any work situation or when people are busily engaged in doing something