When can be say "mahlzeit"?
I do not know it is said only for lunch or every time you look someone who is eating. ex morning.
Mahlzeit is used as a kind of colloquial greeting among colleagues around lunchtime. It's also said if somebody burps (coll. context) or if something goes wrong ("Prost Mahlzeit"). These usages come from the outdated or religious "Ich wünsche (Dir/Euch/Ihnen) eine gesegnete Mahlzeit" (enjoy your meal).
In a formal context it means simply "meal".
As you can see, "Mahlzeit" is a close equivalent to the English "meal", any meal really.
Only used at your workplace - in some companies even the whole day long!
To get the best impression in a funny way: look up on youtube:
Gerhard Polt "Mahlzeit!"
(Gerhard Polt is a famous comedian in Germany, subtle and sophisticated)
https://www.youtube.com/watch?v=vC4t3NPT6gc It's really funny.