It is my understanding that a castling move cannot occur if the king / rook moved. However, in the case where a rook and king move but end up in their original spots, can a castling move occur?
The answer is NO. Neither the King nor the Rook on the side you want to castle should not had moved previously AND there is one important fact, the Rooks should be on the initial position rank!
There were some lacks in rules of castling in chess history and some people made fun of this by creating funny joke puzzles like this one:
An example was composed by Tim Krabbé and relied on a loophole that existed in the definition of castling. In the diagram, White must mate in three moves. The solution begins 1. e7, then the main variations are:
1... Kd3 2. e8=Q gxf3 (other moves allow Qe2#) 3. 0-0-0#
1... Kxf3 2. e8=R! (an underpromotion), and now:
2... d4 3. 0-0#
2... Kg2 3. 0-0-0-0#!
In the last variation, White castles with his newly promoted rook, moving his king to e3 and the rook to e2. Under the rules of chess at the time, this move was arguably legal because the rook had not moved yet. Afterward, FIDE amended the rules to require that the castling rook must occupy the same rank as the king