Salaam,
Regarding Mary, she was in the throngs of labour, and in order to avoid any potential questions being asked of her from other people, God asked her to abstain from talking to them.
For Zakaryia, he was so astounded that he was to be gifted with a child in his old age, that he asked God to give him a sign. This was to satisfy his heart and the sign from God to confirm this miracle, was that he was not going to be able to converse with anyone for 3 days.
This was not abstinence as was in he case of Mary, rather he would physically not be able to speak to anyone.