Think of a star as a big globe with ideal gas inside. Gravity acts as a force compressing the globe, the more it compress, the more energy goes to thermal part since $$dE = TdS-PdV$$ so a shrinking volume decreases $PdV$ term ($P$ is negative in this case, otherwise the system would be expanding), and for $dE=0$ because no reactions are occurring and no photons are escaping. So temperature starts to build up.
Then the as atoms collide they will ionise and start to give rise to plasma conditions (electrons and nuclei flying free from each other). At this point some of the energy escapes the system as photons fly freely away from it.
But the thermal energy of their movement is not enough to counter the crushing gravity until nuclei are fast enough, and the release of energy is slower than the build up due to the compression. Until that fastest nuclei are fast enough that they approach surmounting the Coulomb barrier, and fuse. The release of energy of this fusion releases gammas which are reabsorbed by cooler parts heating them up, while neutrinos escape almost untouched, but with a smaller portion of energy, and residual neutrons and electrons/positrons are produced which are mainly redistributing the energy released in the fusion.
Eventually these events happen so often that the thermal energy produced is enough to counter the gravitational contraction, and the system stabilizes the volume. You can think of this released energy from fusion as an internal energy that is dormant until the system, is forced by compression to release it.
But when enough time has passed, and a large amount of the nuclei fused, the kinetic energy may not be enough to fuse the nuclei newly produced. In some cases, when you have nuclei with masses so large, that is not energetically possible to fuse anymore. Then there is no more internal energy to be released, and the system eventually succumbs again to the gravitational pull, which is kind of the same as the beginning since the mass lost is relatively small.
Further compression "awakes" smaller "reservoirs" of internal energy as the nuclei are compacted further and the nuclear repulsion sets in.
So with this in mind, the temperature of the star should be determined by its composition and its mass. These are like the initial conditions for which you can predict its evolution: if you know how many of each nuclei it has and the total mass you will know how much "latent" energy can be generated from their fusion reactions, and how much gravitational pull there is to trigger the release of this latent energy.
PS: This is an oversimplified picture, but I think the idea is clear. In reality is not that simple to obtain for each star, because there are many reactions to consider and complicated simulations, so only an approximate value of the temperature can be obtained. Luckily we are able to measure star temperature and mass independently to check our results.