When tick label format is not specified, datetime tick labels are automatically selected based on the range of your data and the format of the datetime values. When you zoom into your data, the datetime range changes and the auto tick labels are updated as needed.
When you specify a tick label format, the auto features are turned off. You're essentially telling MATLAB that you want to format the labels so MATLAB stays out of your way. The automatic adjustment of tick label formats are turned off so zooming does not update the label format.
You could detect when the axis range changes using the LimitsChangedFcn which is evoked when the axis limits changed (e.g. when zooming; see Community Highlight). It might take some fine tuning but the function would update the tick label format following a set of rules.
In this demo, the tick labels are set to auto when the range of the datetime axes is less than 2 minutes or there are less than 2 ticks. Otherwise, it returns the tick format to a fixed format.
d = datetime(2023,1,17,23,59,0) + minutes(0:0.1:150);
y = hours(d-d(1)).^2 + .15*rand(size(d));
h = plot(d,y,'DateTimeTickFormat','yyyy-MMM-dd hh:mm a');
ax.XAxis.LimitsChangedFcn = @XLimitsChangeFcn;
limitRange = diff(limits);
nTicks = numel(ruler.TickValues);
if limitRange < minutes(2) || nTicks < 2
ruler.TickLabelFormatMode = 'auto';
ruler.TickLabelFormat = 'yyyy-MMM-dd hh:mm a';