The thing is Git that in Moonwalker people already knew the songs on that game, they weren't new compositions so people could tell from the beats what the song would be. With Sonic 3 we are talking about brand new compositions and this is their only form of representation is on this Sega Genesis console. He did talk with the Sega sound team and tour frequently around that time and he did create tracks for the majority of the game, one employee claims to have recorded answering machine tapes of MJ humming the tunes. Most likely what happened was he showed this stuff to the Sega composers and some other music he was working on, and when it came time to make the soundtrack they were very, very, very, heavily inspired by the stuff he was working on or whatever compositions he had given him. Also, You Rock My World is definitely not in Sonic 3.
The game is Sonic's Genesis Collection on PS3 which says "Michael Jackson was originally hired to compose Sonic 3's soundtrack" when loading the game as a trivia thing. So what we have here is not the direct work of MJ but although they didnt sign him on for whatever reasons, whether it be his dissatisfaction with sound quality, the allegations, or monetary reasons, it is apparent that bits of his compositions did get out there through the Sega Audio team who heard this stuff from him. They probably just remixed certain tunes or added different things so they wouldnt get sued for any potential copyright.