I think everyone is getting a little too rambunctious here. The OP asked a legitimate question about the technical operation and the design of the AR whether you like it or not. You guys all need to settle down. we tend to add tone to something that has no tone; text. If we were all sitting around the table and the OP asked the question, the discussion would have gone a lot different.
So to the OP’s question: Why the buffer in the AR15.
Simple answer. The AR15 was designed from the AR10 (7.62mm). So now the question surely becomes why the buffer design in the AR10.
Another simple answer. It was a matter of genius. What you may think is a flaw, is actually a super idea. You see, you first have to understand the AR10. At least the original AR10 submitted for trials to replace the Army’s M1 Garand in the late 1950’s. Albeit, it lost severely do to the aluminum/steel barrel melting during a torture test.
Why the buffer? Well, due to the AR10’s adjustable gas system and the DI functionality along with the convenient features of the AR10 like the inline stock, it was clear that a spring was needed. I am sure it was likely tested (assumption here) by the designers without a buffer and they found it necessary to introduce one.
Now, keep in mind that the AR10 was designed to be a 20" barreled rifle. Not a small 14.5" barrel with a collapsible stock M4 or shorter. So fitting it into a car or other vehicle was never in mind. In fact the rifle the AR10 lost to, was the T44, later known as the M14. So considering the M1, M14, etc and the types of rifles used previously by the military, folding stocks just were not considered. Albeit, I do believe the FAL was one rifle that was in the same competition.
Anyway, the bottom line is that the buffer is necessary to the unique design and features of the AR platform. The inline stock with the bolt carrier and rotary locking bolt, it just simply required the usage of a buffer.
Is it a flaw? It could be argued either way if one is being honest. I personally do not find it to be a flaw. The design was designed over 60 years ago with a specific mindset. Over the years it has evolved and now with SBR, etc you can have an AR15 so small and with so many different calibers, a folding stock is just one more possible point of failure.
Keep it simple… keep it working.