This isn't meant to be a political question—people have been calling countries "it" since long before feminism was a thing. Calling a country "she" in most contexts would draw attention to itself as an odd affectation—it certainly wouldn't go unnoticed. I've been binging history books over the last couple years, and this usage, even in recent books, always jumps out at me.
(Before someone starts making some comment about it being a relic of Anglo-Saxon having had gendered nouns, the Anglo-Saxon land was of neuter gender, not feminine; this argument is often brought up to "explain" ships being called "her", when the Anglo-Saxon sċip was also actually neuter.)
EDIT: Some more examples form books I've read recently:
A Concise History of Germany by Mary Fulbrook (2019):
Battle Cry of Freedom by James M. McPherson (1988):
A People's History of the German Revolution by William A. Pelz (2018):
1848 by Mike Rapport (2010):
Iron Kingdom by Christopher Clark (2007):
Crucible of War: The Seven Years' War and the Fate of Empire in British North America, 1754–1766 by Fred Anderson (2001)
What are some specific examples from books? What specific books and authors? Are they written in English (or maybe translated to English?) I have a range of books on ancient history from Sumer through the Roman empire and I don't believe a single one does this. I would find it pretty odd in any kind of serious work. I'm curious where you're seeing it (especially frequently, and in recent books).
The best I can do in the meantime is this discussion from u/Noble_Devil_Boruta on the use of terms like mother and fatherland, but that's a different thing from what you're describing.
https://www.reddit.com/r/AskHistorians/comments/c2tr34/why_were_germany_and_russia_known_as_the/
If you could provide specific examples of this, I might be able to answer better, but from my own experience, it tends to be because a country is viewed as a "motherland" (with fatherlands being referred to as "he"). There's a human tendency to try to anthropomorphize big and abstract things so that we relate better to them, so narrative approaches to history will seek (consciously or not) to make a nation feel like a person.
As for why nations pick a mother or father to represent them, that's a bit of a trickier topic. Obviously, there's the parental role (looking after citizens, raising them, asking citizens to look after them in return), and it's often split based on more "traditional" parental roles: "motherland" is used to evoke feelings of compassion, caring for its citizens like children, while "fatherland" is often more strict, often militaristic.