sora has, and always will be, the immature character who sometimes says or does things that are not quite smart
but don't forget, he's always been this way
he may have been serious in kh1 and kh2, but he was still funny sometimes
in kh1, yes, he was quite serious seeing as both his friends were nowhere to be seen for a little while. but as soon as he found riku, he got a little better and knew that riku was safe, now he had to worry about kairi. eventually, when he knew where kairi would be, he was able to rest easier. all he had to do was look for riku now.
khcom he was still like the sora of kh1. he had times where he was quite happy and having fun, but he also was being serious when he needed to be, regardless of memory alteration, and so he had a small balance between them.
kh2 came around and sora grew up....but he was still pretty happy go lucky. he was still resting easy because he knew where kairi was for most of the game. he just needed to find riku of course. then, as the game progressed, he got more serious and determined to stop the organization. yes, he was goofy in worlds, but that was because he had never experienced a few of them. and the ones he had experienced, he acted chummy with the ones he knew.
all i can tell is that the reason sora doesn't really act serious most of the time is because he doesn't know anything about the worlds and he's trying to explore. he's still a teenager, he's not seen some of the things riku has had to go through. in all honesty, that's what makes those two so different. sora hasn't had to see the dark side of the worlds or get himself taken over as bad as riku had. riku has, by far, had the worst experience after leaving his homeworld. he's had to fight every step of the way, with little to no rest. in fact, don't forget that at the end of kh2, he was able to joke with sora because he was finally able to take a rest and not fight anymore.