It was never stated outright, but we know it's true because of the fact that he has a commissioned Starfleet rank (Lieutenant in Season 1 and Lieutenant Commander currently)
People mistakenly took his behavior and his attitude towards Lorca and being assigned to the Discovery to mean that he was a civilian or NCO who got 'conscripted' into joining Starfleet's war effort, but that was never actually the case.
I mean, this could be, but it's absolutely not a sure thing. The actual dialogue can be interpreted as Stamets being or not being part of Starfleet. He says that "we were happy in our lab, then your war started, and Starfleet co-opted our research. They split us up, put us in charge of different teams, so we could work twice as fast."
In the comics, he's definitely not part of Starfleet and, if I recall, those comics have informed the actors' perception of the roles. Not canon, but certainly confirmation that an alternative interpretation is possible.