Mahlzeit usually is not the phrase used before tucking in (we use Guten Appetit as a starter-gun phrase at the table) but rather the time-of-day greeting, mostly at a workplace when greeting people at lunchtime (irrespective of whether they are going to have lunch, are just having lunch or already had lunch).
E.g. when you encounter a coworker in the corridor in the morning, it’s Guten Morgen but when it’s already lunchtime it’s Mahlzeit.
When you and the same coworker have their day off and you happen to meet on the street at noontime, it’s not Mahlzeit but Guten Tag.