The answer to the "why" is that boxplot, for reasons I've never been able to figure out, doesn't just change the tick positions and labels. Instead, it removes the xticks completely (or y-ticks, in the case of a horizontally-oriented boxplot) and replaces them with text annotation objects. And annotation objects are positioned relative to the figure, not the axis. Apparently slightly differently each time (possibly due to the fact that boxplot also, for reasons unknown, resizes axis, hence changing the figure-to-axis ratios between calls).
The easiest fix:
delete(findall(gcf, 'type', 'text'));
set(gca, 'xticklabelmode', 'auto', 'xtickmode', 'auto');
Best Answer