If Jesus was really God, why did Satan try to tempt him? Doesn’t he know that God can’t sin?
Yes, he does know, which is why he tried to tempt him. If Jesus had succumbed to the temptation, the devil would have known that Jesus wasn’t the real Messiah.
Remember, the devil isn’t God. He isn’t omniscient or infallible and so doesn’t know everything. He can make mistakes. As Aquinas puts it:
The minds of demons are utterly perverted from the Divine wisdom, they at times form their opinions of things simply according to the natural conditions of the same. Nor are they ever deceived as to the natural properties of anything; but they can be misled with regard to supernatural matters; for example, on seeing a dead man, they may suppose that he will not rise again, or, on beholding Christ, they may judge him not to be God. (ST I:58:5)
Thus, to establish that Jesus was God, the devil needed to do a little testing.