originally it means sth like "whatever god wishes/its all gods wishing"
in islam, there is a concept called 'nazar'. it means glance. when someone likes something a lot or envy it, it is believed that a bad energy goes to that thing from their eyes. so something bad may happen to it. 'nazar deveyi kazana insanı mezara sokar' they said. so if someone likes something a lot and doesnt want any harm to touch it because of them, they say 'mashallah' to remember themselves that the source of that beautiful thing is not the thing itself, Allah wished it to be like that.