When calling plot or axes you can optionally specify a "parent" or "container", where the axes or plot object gets created in. The container is the handle object to the object where the new object will be created in. If you don't specify the container, it will be created in the "current figure" or "current axes". This can be literally anything you created or selected with your mouse before.
If you call plot and no current axes or figure exists, it will create the missing figure window, create an axes object inside it and then creates the plot into the axes.
See this example which creates some figures and uses a button in one window to plot something in another window (also attached):
h_fig1 = figure;
h_fig2 = figure;
h_fig3 = figure;
h_ax2 = axes(h_fig2);
h_ax3 = axes(h_fig3);
h_fig1.Position(3) = 350;
h_fig1.Position(4) = 100;
button_plot = uicontrol(h_fig1, ...
'String','Call Plot in Figure specified as h_fig3', ...
When pushing the button to plot inside h_fig1, the target container needs to be specified. If you change the Callback-Function from this:
The error you described occurs, as the plot command creates an axes in the current figure (which is the figure with the button) because there is no axes to plot into.