All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
The scholars defined spying to be: striving to know people's affairs which they are keen on concealing and which they do not like others to find out about them.
Abu Al-Hilaal Al-‘Askari said in the dictionary of linguistic differences: “The Saying of Allah (which means): {And do not spy.} [Quran 49:12], means that it is forbidden to look for the faults of others and their secrets which they do not approve to be disclosed and they do not like others to know about it.” [End of quote]
Therefore, it is not permissible to find out any information that falls under this criterion, even if it is authorized by law, unless there is a predominant benefit, because it is permissible to spy in some cases.
However, if the person has willingly provided the information, and he knew that the public would have free access to this information, then it is permissible for one to obtain this information from the source to whom the person had provided the information.
For more benefit, please refer to Fataawa 224389, 30115, and 16126.
Allah knows best.