The military needs its own medical assets so it can treat soldiers in times of war. For security purposes, it needs medical facilities and medical personnel under its own control. It isn't sufficient for there to be sufficient civilian facilities.
Military dependents get free medical care in part to keep doctors busy with real cases during peace time.
Military members and their dependents cannot file malpractice suits. There are people who are very unhappy with this fact. Mistakes do happen. When they happen, you don't have recourse to sue and this is a point of contention for some people.
They also have world class facilities. If something goes seriously wrong, you can get referred to one of their regional hospitals.
I'm alive in part because we happened to be stationed at a base with a regional hospital when things went badly sideways for me. It served military personnel in eight states. It was a teaching hospital with connections to UC-Davis Medical in Sacramento and, I think, Stanford in San Francisco. I had testing in both cities. I got a cutting edge diagnosis. That was a turning point in my life.
For the record, I think we need a single payer system in the US. The current civilian medical system is seriously broken.