Up until quite recently in history most food establishments, and also the majority of stores, closed fairly early in the evening and stayed closed all night.
There were basically two options for an officer working the graveyard shift who wanted a snack and a cup of fairly good quality coffee- diners and doughnut shops, both of which were regularly frequented by the police.