You have discovered a fascinating nugget from the subject of
algebraic number theory.
It is a theorem that if every prime p of the form 4n+1 can be written as a sum of two squares: 5 = 1 + 4, 13 = 4 + 9, etc. Conversely, no prime of the form 4n+3 can be (reduce it mod 4).
Let Z[i] be the set in which you're doing arithmetic, of complex numbers of the form a + bi, where a,b are both integers. These are called the Gaussian integers [1].
If p = a^2 + b^2, then p = (a + bi)(a - bi) in the Gaussian integers. So that means that whenever p=4n+1, p is no longer prime in Z[i]. So you shouldn't expect the machinery of Fermat's little theorem to work. Conversely, any prime p=4n+3 is still prime in this bigger set, and so the machinery underlying Fermat's little theorem still works.
The rabbit hole goes very deep :)
[1] https://en.wikipedia.org/wiki/Gaussian_integer