I have seen similar behavior on vehicles that have a dying alternator. The issue is that one vane of the rotor (or maybe stator?) has shorted and no longer functions. If when the car is shut off and the rotor stops in a particular position the alternator won’t work. Give it some time and with heating/cooling moving things around just a bit plus the act of repeatedly trying to turn it on potentially making it move just a bit, and it works fine.