In New York around lower Manhattan I saw some storefronts with these boxed doors outside.
What are they called and what is their function?
That is a sidewalk vestibule. The idea is to have an extra door between the building's interior and the outside, so as to reduce the amount of air exchanged when people go in and out. In winter, warm air stays inside and cold air stays outside, reducing the building's heating costs and avoiding uncomfortable drafts for diners sitting near the door.
You could also have a vestibule inside the restaurant's regular doors, but that would occupy valuable floor space, and would be useless during warmer seasons. The temporary vestibule can be put up in winter and taken down in summer.