Looking up hermaphroditic tendencies in frogs, as one does, and I found this fascinating paper via Wikipedia:
https://opus.bibliothek.uni-wuerzburg.de/opus4-wuerzburg/frontdoor/deliver/index/docId/3146/file/Linsenmair_Protogynous.pdf
The most interesting part to me is just speculation, but one idea for why females might change into males after laying some eggs is that although males enjoy more reproductive success overall, because they defend territories and attract females using vocal calls, they're potentially more vulnerable to predation by animals that hunt based on sound.
So basically, first ensure you have *some* offspring by being female and laying eggs, then once you've done that try to have *many* offspring by changing into a male, vocalizing to attract females, and fertilizing their eggs (unless the vocalizing gets you killed or other males out-compete you).
Sadly this is pure conjecture and the sex changes were only observed in the laboratory, not the wild.