The behavior is deterministic, but the behavior depends upon more than is obvious.
Any time you execute a graphic command without explicitly specifying what figure or axes it is to apply to, then it applies to the "current" figure or "current" axes.
Creating a figure in the form you use is defined to make the figure current.
The imagesc() that you do in the instruction after that will work on the current axes. If the figure(1) call ended up creating the figure, and if figure 1 is still current, then there is no current axes and one will automatically be created and made current and then drawn in by the imagesc()
A key point in that description is "and if figure 1 is still current". If there has been no keyboard or mouse or debugger interaction, no graphic callbacks (calling figure() is specifically defined as one of the occasions on which queued graphics callbacks might be run), no timer callbacks -- if "nothing happened" between the time the figure was activated and the time the imagesc() is run, then figure 1 will still be the current figure. But a timer or graphics callback might have changed that.
More particularly, if you clicked your mouse for any reason after the figure was created, then the current figure might have changed. If your window manager asks you specifically position each window, then you would have clicked and MATLAB's idea of the current figure might have changed. If you hit a breakpoint and you clicked to bring up the command window, or if you moved a window in order to show the command window, then MATLAB's idea of the current figure would have changed.
What is recommended to avoid this problem is to always, in every case, specify the object that the graphics command is to happen against. You might find this referred to as "always parenting" your graphics. For example,
fig1 = figure(1);
ax1 = axes('Parent', fig1);
imshow(myimage, , 'Parent', ax1);
fig2 = figure(2);
ax2 = axes('Parent', fig2);
imshow(myimage2, , 'Parent', ax2);
plot(ax2, x, y);
You might have noticed here that some commands allow an axes to be passed as the first parameter. Others require the 'Parent' option. Some commands support both syntaxes; the ones that support passing in an axes almost always allow 'Parent' instead.
If you encounter a graphics creation command that does not permit an axes or a 'Parent' to be passed, then the implication is typically that it is going to create a new figure of its own. However, sometimes the implication is that it is going to more or less erase any axes in the current figure and draw something. (Some of the video players do that :( )