Why are Locomotives Called a She?

Unlike old English, where every noun was treated as either masculine, feminine, or neuter,  Modern English largely lacks grammatical gender. However, in some cases, feminine pronouns are used by some people when referring to ships, airplanes, to churches, and to nation states and islands.
In many other languages, objects have gender. You can refer to them as the feminine or the masculine. Russian, French, Spanish, and Arabic are all examples of such languages. In French, wine and chocolate are masculine, table is feminine while masculine in German.  In Arabic, soup and the calendar year are feminine.

Why are locomotives frequently referred to as she and her?

It seems like there’s a debate in the railway world, whether a steam locomotive is classed as a ‘she’, although for as long as steam locomotives have been around, crews have referred to it as female. “She” and “the old girl” are synonymous with steam locomotives.
The reason for that is probably due to the engineer’s connection with the locomotive, speaking of “her” as a she, a living creature.
Other examples would be:

Earth. she could be appropriate for our planet. Mother Earth
Hurricanes. In 1953,  Meteorologists began naming hurricanes with female names, just as naval meteorologists, who named the storms after women(just as ships at sea were named for women)
Vehicles often take feminin gender

In the end, it’s a matter of personal preference!