As far as I know, Latin had a word-initial accent for some time of its history after losing the Indo-European accent. I am wondering why Latin then switched to an ante-/pen-ultima stress pattern.
I'm afraid the most satisfying answer I can give is, these things just change over time, without a solid reason. It's like asking why the vowels in Middle English chain-shifted so dramatically: vowels just tend to shift, and there's no universal pattern to it.
In Old Latin, in particular, the stress had already shifted from the complex rules of Proto-Indo-European to something much simpler: the accent was always on the first syllable, no matter what. This may have been an areal feature, since the same rule happens in Etruscan, but unfortunately we don't know enough about Etruscan's history to say which language affected which here.
Somewhere around the time of Plautus, this started to shift. The first change only affected words of four or more syllables: in these words, the accent drifted forward until it was no more than three from the end (that is, on the antepenult). I don't know why this happened, but it also happens in modern English: less than a century ago, four-syllable adjectives like "despicable" and "lamentable" were accented on their first syllable, but now the stress has shifted more toward the center.
Separately, but around the same time period, another rule took effect. If the accent came right before a "heavy" syllable (a syllable with a long vowel and/or a coda consonant), it shifted forward onto it, as long as this wouldn't push it onto the last syllable. This isn't uncommon cross-linguistically: as TKR put it, heavy syllables tend to "attract" stress to them.
And thus, by the time of Cicero and Caesar, the famous stress rules of Latin were established: never accent the last syllable (the ultima), accent the one before that (the penult) if it's heavy, otherwise accent the one before that (the antepenult).
Unfortunately, I don't think that there is any known satisfactory explanation. "Why" questions can be difficult to answer even for well-documented linguistic phenomena, and I have the impression that we don't even know much about when and how the penultimate/antepenultimate stress pattern of Classical Latin developed.
There's not much evidence about Latin accent (and changes over time)
As far as I can tell, there is little good evidence about Latin accentuation. It was not marked in the writing system, and I don't know of any visible effects the later (non-initial) stress patterns had on other aspects of Latin pronunciation, except for in post-Classical time periods (note that the Latin SE question "Did Classical Latin stress impact any sound changes?" didn't get any answers with examples from before the Romance, or at earliest proto-Romance time period). There are some descriptions of Latin accentuation in ancient grammarians, but their accounts are considered unreliable for reasons that I discuss in my answer to a Latin SE question about the accentuation of adverbs.
People also have argued about what exactly Latin accent was (e.g. stress vs. pitch).
Apparently, even the idea of a word-initial-stress stage in preclassical Latin is disputed (something I didn't know before writing this post): see Pultrova 2011.
Ideas about stress in Plautus (~200 BC)
Some people try to get evidence about early Latin accentuation patterns from the works of Plautus, but what I have read gives me the impression that this is a really difficult task.
"Ictus" = stress?
There is a concept of an "ictus" which debatably could have corresponded to accent or stress, but Fortson (2008) says "There is great disagreement about its nature and whether there even was such a thing in Plautine poetry at all" ( p. 30) and Christenson (2000) says "the ictus about which modern scholars still debate, often along national lines -- may be entirely anachronistic.201 [...] 201 The arguments of Gratwick (1993) 40-8, 59-62 are followed closely here" (p. 69).
"brevis brevians"/"iambic shortening" conditioned by stress?
The phenomenon of "iambic shortening"/"brevis brevians" ("BB") is often supposed to have only affected unstressed syllables (or in some theories, specifically syllables in weak position in a foot). But I don't know how strong the evidence for this is.
Christenson (2000) says (in a section on "iambic shortening") that "Disyllabic forms of ille, iste and ipse were originally accented on the last syllable and so we find, e.g., Am 270 quid ĭllíc, 415 et ĭpsús" (p. 63).
However, Fortson (2008) indicates that there may be some challenging counterexamples to the idea that BB was affected by accentuation. Fortson acknowledges that BB is "not supposed to have affected tonic syllables" (p. 207), but then goes on to say that "the aggregate of evidence that BB could affect the second syllable of trisyllables is far too great to be easily dismissed [...] Cross-linguistically, while tonic syllables resist syncope, they are not immune to shortening and other reduction processes; we must simply try to recover the conditions (if any) under which this was possible in Plautine Latin" (p. 208).
Preantepenult stress in Plautus
I have seen several sources that say that LLLσ quadrisyllables in Plautus could have initial stress. As with BB, I don't know how we know this; Pultrova 2011 suggests that it is based on the controversial idea of the "ictus" corresponding to the stress accent (p. 224).
I found one example in this PDF (which is also the source that pointed me to Christenson): stultitia is the example given (I don't know what's up with the first syllable apparently being light here: while I have read that some consonants that were codas in Classical Latin did not always make a preceding syllable heavy in Plautus' work, I'm not sure why that would happen in this case). Another source I found that gives this as a rule is MacCary and Willcock (1976) (p. 212).
I was able to find a paper that discusses this phenomenon in more depth and that confirms that apparently, we only see this phenomenon when the pre-antepenult syllable is light: "Why preantepenultimate stress in Latin requires an OT account", by Haike Jacobs. Unfortunately, so far I've only been able to access it partially, through Google Books.
Anyway, all of these sources do say that the accented long penult rule was active by the time of Plautus, so if they're correct, then weight-based stress rules apparently became a part of Latin's prosodic system before the "stress window" had become absolutely restricted to the last three syllables.
Theoretical analyses of the Classical Latin stress pattern
There is a ton of literature about how to analyze the Classical Latin stress rule according to various phonological frameworks/theories, but I thought I'd add a brief, simplified description of just the main theoretical concepts that I've seen applied, since some of the comments have brought up some theoretical topics/terms. If you have further questions about some aspect of metrical theory or comparative typology of metrical systems, I'd encourage you to ask a separate question so that people can post more detailed answers focusing on that.
Pretty much all of theories that I'm familiar with recognize moras, syllables and feet as separate kinds of units that all have relevance to Latin prosody. If you're not familiar with these theoretical concepts, you can ask a separate question about how they are applied in analyses of Latin.
In an Optimality Theory (OT)-type account, the Classical Latin stress pattern is thought to emerge from a number of "violable constraints" on foot structure and the parsing of syllables into feet. Here is a non-technical summary of the kinds of things that these constraints are often thought to do.
"Extrametricality" of word-final syllables. The last syllable of a word is assumed to be unfooted. Of course, monosyllables would have to be an exception to this. Disyllables (specifically, ones where the first syllable is light) are also problematic and often said to be exceptions to final-syllable extrametricality. But the extrametricality analysis is supposed to make it easier to explain the stress pattern of trisyllables and longer words.
Parsing of the non-extrametrical syllables in a word proceeds from right to left. Parsing of syllables into feet is not always exhaustive: for example, LLLσ words are as far as I know uncontroversially analyzed as having (in Classical Latin) the structure L(LL)σ, with an unfooted initial syllable.
Latin foot structure is "binary". There is some debate about what kinds of feet are permitted in Latin (I think a lot of this is part of more general theoretical debates about "foot binariness"), but it seems to be pretty generally held that Latin has (LL) and (H) feet, but not (L) feet. That is, there are no monomoraic feet. (LH) feet seem to exist in disyllables at least; I'm not sure how their existence is accounted for. The extent to which Latin made use of (HL) feet seems to be debated; Mester (1994) argues that HLσ words were parsed as (H)Lσ rather than as (HL)σ.
Disyllabic feet have a "trochaic" stress pattern. Somewhat confusingly, in this context, "trochaic" is used with the modern English meaning, not with the classical meaning—it is not about length, but about stress falling on the first syllable of the foot.
Primary stress falls on the last foot in a word. In a word with a heavy (bimoraic) penultimate syllable, the penultimate syllable by itself would constitute the last foot, while in a word with a light penultimate syllable, the last foot would consist of the antepenult along with the penult (or possibly just the antepenult, if we interpret Latin feet as being maximally bimoraic and say that a light penult is allowed to be "unfooted" when it is preceded by a heavy antepenult).
You can see some specific examples of constraint sets given in various OT papers, like Apoussidou and Boersma (2004). If you think that violable constraints like the ones listed in that paper represent something real about what was behind the phonological system of Classical Latin, then you might try to identify how a change in their relative rankings might have caused a transition from word-initial stress to weight-sensitive stress.
Apoussidou, Diana and Boersma, Paul. 2004. "Comparing Two Optimality-Theoretic Learning Algorithms for Latin Stress"
Christianson, David. 2000. "Amphitrvo"
Fortson, Benjamin. 2008. Language and Rhythm in Plautus: Synchronic and Diachronic Studies
MacCary, W.T. and Willcock, M.M. 1976. "Casina"
Mester, R. Armin. 1994. "The Quantitative Trochee in Latin"
Pultrová, Lucie. 2011. "From the Proto-Indo-European to the Classical Latin Accent"