There are a lot of reasons to see out of place locomotives that I don't know if they could all be listed.
I'm sure most know of situations where units were bought but not painted yet.
Another includes preservation, the Chinese steamers in KY mentioned, they were obtained for preservation as the last of their kind.
Yet another includes power pools including agreements that carry over into mergers. Power pooling causes interesting results. For one, I never know that New York Central did it until I bought an NYC book with a page on the subject and it listed the 7 known major pools they had, who they were with and where they traveled, it also had the first time I saw NYC deisels mixed with another railroad, in this case Rock Island. Some of these power pools carry over into mergers, such as Penn Central/Conrail units mentioned on Boston & Maine lines, NYC and B&M had a pool run so this would carry over into PC/Conrail. This is one of the harder things to trace because from what I've seen pictures of pooling in certain years are hard to find.
Then there is also detour trains, situations where one railroad has a certain protion of one of their lines out of service so they make an arrangement to run trains over another railroad's lines in the area. There was an article on this in a Railroad Model Craftsman in the past year showing one guy's Reading layout and he ran Central of New Jersey trains over the lines as detour trains.
And there's times where one railroad had some kind of investment/ownership in another. Example, Pennsylvania once had investment in Lehigh Valley so PRR locomotives were found on LV tracks (maybe vice versa also). B&O/CNJ described below is similar. Also some railroads like NYC would use similar paint schemes but different letting on locomotives for other railroads, when under NYC ownership P&E and P&LE deisels had NYC colors but home road lettering.
Wildest story I know of, Baltimore and Ohio leased some SD40s to Central of New Jersey. Even though lettered for CNJ, it said they sometimes wound up in B&O/CNJ power pools that found the CNJ units on B&O rails and vice versa. B&O also did pooling with Southern Pacific so B&O units went west on SP rails and SP units were in the east on B&O track. One time a CNJ unit somehow wound up in a B&O/SP pool train resulting in a Central of New Jersey SD40 unit going west (doesn't mention the engine number).