Your questions have several explanations, I will try to make it easy and from the European mode of operation that I suppose was similar in part to the American.
Steam:
The steam locomotives for passenger trains had a steam-driven electricity generator for the lighting of the train and some coupling hoses to transmit the electricity to the coaches (only for the lighting).
Diesel:
Most diesel locomotives are actually diesel-electric; A large diesel engine generates electricity to power the electric traction motors placed on the axles of the bogies and in the diesel passenger locomotives there is a converter and couplers to transmit the lighting and heating current to the train.
In both steam and diesel, the classification of passengers or freight is not only for that and it is not the subject of this thread.
Regarding the classification in diesels, for example the Alco F were for freight and the Alco P for passengers.
Coaches and wagons:
Most passenger cars had battery boxes at the bottom and a dynamo too or one in each bogie to charge the batteries.
The main purpose of these batteries was to power the lighting system of the train when it was stopped and without a locomotive.
But as I said there were many operating systems.
This system was also used by some wagons such as mechanical reefers to keep the cold at stops, although for a lot of consumption there were or are exclusive generator wagons for refrigerated trains like the Russian ones. In Spain, I have seen a platform with a couple of 20 generator containers on an isothermal container train.
I hope I have clarified your question a bit.
Regards, Javier