This is based on the examples given in the comments. I've tested it in R2015b and R2019b, so I'm assuming it would have worked circa 2017. This does not work on docked figures.
% you have a populated figure (has a descendant axes)
hFig = figure;
plot(rand(100,1));
drawnow
% mute the warning
% i don't know which exact version this changed in
warning off 'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame' % older versions (effective in R2015b)
warning off 'MATLAB:ui:javaframe:PropertyToBeRemoved' % newer versions (effective in R2019b)
% Get the underlying Java reference
jf = get(hFig,'JavaFrame');
jw = handle(jf.getFigurePanelContainer.getTopLevelAncestor,'CallbackProperties');
% set some example focus callbacks
set(jw,'WindowGainedFocusCallback',@(x,y)disp('given focus'));
set(jw,'WindowLostFocusCallback', @(x,y)disp('lost focus'));
That said, I don't know if this still works in modern versions. It fails in the forum editor, though I'm not sure if that's just a forum thing or if the JavaFrame property has finally been removed. Unfortunately, that seems particularly likely.