First off, I suspect you are misunderstand the purposes of the different codecs. the job of FLAC is not better "sounding" audio (although it may sound a little better), its for archival audio. with FLAC, you can decode and reencode the file over and over without loosing any quality ever. With mp3, If you decode it and reencode it a few dozen times the final result would be unrecognizable. Encoding mp3 to FLAC is pointless because it will only take more space and sounds exactly the same as the mp3.
But to answer why: The full answer is vey complex, and requires understanding of information theory. But I will try to summaries it.
The short answer: MP3 is lossy, and flac is lossless, meaning mp3 has the option of removing or inserting information in the data, making the compression more efficient. FLAC can not do that.
The long answer:
Let use English as a compression algorithm. follow these directions:
"Write 1000000 zeros to text file".
If you do that, the final file will be about 1Mb. But using english, I was able to describe (compress) it to just one short sentence that if written to a file would take only 32 bytes. Not let's change the sentence a bit.
"Write 500000 zeros to a text file, then write one 1, then write 499999 more zeros".
Now this sentence is MUCH longer, (82 bytes) and produces a file that is nearly identical, except for one value in the middle. That one random value in the middle made our sentence (compressed data) more than twice as large. You see, the more predictable something is, the better it compresses. How "compressible" a piece of data is determined by its "information entropy" or randomness. The higher the entropy, the worse it compresses. The limits of compression are known and can be calculated using information theory.
MP3 is lossy. Meaning it can look at that seconds sentence, and decide that the extra '1' in the middle of the files will never be noticed, and change it to a zero, Thus reducing its entropy, thus improving compression. The 1 is now lost forever though, and can never be recovered. This process is called 'quantization' an is one of several reason mp3 can achieve its compression ratios
But mp3 also does the opposite too. Due to mp3 conversion of data to the frequency domain, along with psychoacoustic optimizations, it can actually increase the entropy of the PCM data when decoding. If you then take the PCM and encode it with FLAC, FLAC will persevere the added entropy.
Flac uses a totally different compression technique to ensure entropy is preserved and not quantized out. This means flac needs more space to encode files. The fact that FLAC does not quantize is the reason for its existence in the first place and is its primary feature.