Aye! The first column is not "sorted according the second column" (only half an explanation). The block of numbers in each row is treated as a fixed unit, and each row is rearranged such that the values in the second column are sorted in ascending order.

"find the longest diagonal arrangement of primes in spiral(n)" leaves room for misinterpretation.
I would have quickly understood:
"return the length of the longest diagonal sequence of primes in spiral(n)"