OOPS! I FORGOT THE KING!
The Puzzle That Stockfish Can't Solve
Mainstream chess engines are designed to play games and solve game positions. If you give SF the full game preceding the diagram, it will solve your problem correctly.
You can make the puzzle more tricky by offering the Qa1 and ask whether black can save his king😏
The answer then is YES!

Mainstream chess engines are designed to play games and solve game positions. If you give SF the full game preceding the diagram, it will solve your problem correctly.
You don't have to give the entire game, but you do have to supply the correct castling rights, e.p. rights, etc. when specifying the starting position. The OP is right about Stockfish not being able to calculate backwards. Stockfish wasn't designed for retrograde analysis.
Mainstream chess engines are designed to play games and solve game positions. If you give SF the full game preceding the diagram, it will solve your problem correctly.
You don't have to give the entire game, but you do have to supply the correct castling rights, e.p. rights, etc. when specifying the starting position. The OP is right about Stockfish not being able to calculate backwards. Stockfish wasn't designed for retrograde analysis.
Of course, giving castling rights is sufficient in this instance, but my reply was generalized to include all uncertainties in game histories such as who-is-on-move-issues, e.p. rights and potential for repetitions or 50-move claims. It is also true for chess960 - with funny castlings - and most chess variants with funny rules the engines will conquer in the future.
You can make the puzzle more tricky by offering the Qa1 and ask whether black can save his king😏
The answer then is YES!
Nope, he can castle! Placing the queen on a1 does not imply that white's last move looked anything like Qa6-a1 like you apparently assume!
Unless you actually intend to give the move Qa6-a1 to the solver but how would that be more tricky?
In this position, white has a mate in 2.
It is after 1.Qa1 Kd8 (or Kf8) 2.Qh8#. However, Stockfish thinks that after Qa1, Black can castle queenside. However, there is a way we can prove that Black can't castle. If we go to the beginning, notice how the pawns are on their starting squares. This means they could have never moved, meaning that the rook or the king must have moved on the move before this position. And since the chess rules clearly say you can't castle after you've moved your rook or king, this means that Black can't castle. The reason why Stockfish doesn't know about this is because it was made to calculate forward, not backwards.