Teams that are behind in score generally send their goalkeepers up front for a corner kick/set piece in the last seconds of the game.
Why are GKs not being sent up front when the result is a draw and the time has expired and it’s clear that the set piece/corner kick will be the last action of the game? The captain could surely confirm with the referee that the corner kick will definitely be the last action…
Is there a rule that prevents the referee to calling the game while the goalkeeper is in the opposing box or are teams just too scared that the ref will allow a potential counter attack?
It’s a gamble. Keepers have been caught out by a quick counter before. If you’re already losing then there’s nothing to lose. If you have a point secured it’s too risky (unless you needed the extra point to win the league/avoid relegation).
The ref can’t say if it’s the last play. Not only does it risk influencing the game, if there was a foul etc. they’d still need to call it, or they might decide that there was time wasting that needed adding to the clock. Referees don’t just wait for an attack to finish before blowing, they also need a moment when there is little possibility of infringements etc.