The idea of the head scarf was to protect them from the sands and wind of the deserts and the sun, had nothing to do with religion. As Mary was alive five and half centuries before Islam was founded the fact she wore a headscarf was because of the reasons I have given above.