Is "randomly" being used literally or in the colloquial? In other words, did it suddenly without a known correlation cease to start at all if hot, or does occasionally (without a known correlation) not start when hot? Also, where/what was jiggled that made it work initially?
With the information at hand:
It sounds like thermal expansion is causing whatever had a weak connection to lose that connection until it cools and contracts again. The thermal expansion could be taking place within the starter itself (which would cause it to test fine), or anywhere along the signal path back (obviously in proximity to things that get hot). Given the successful jiggling, I would start at the starter terminals and see if there is any movement at all within the starter itself.
There's also the possibility that some wires got where they weren't supposed to go and some insulation was melted. When the part that did the melting is hot, the culpable wire is grounding to the engine versus carrying the signal/current through to the starter itself. That could also potentially cause lights to sporadically dim (unless you're talking about the dimming that occurs due to the additional power draw typically used by a starter) as power is effectively shorting through the block (though with enough resistance to not blow a fuse). The net result is effectively the same: follow the starter wires all the way back to the source only look for melted wires in addition to loose connections/worn electrical parts.
An automotive multimeter would be a good investment here if you don't already have one as it can be used between wires and components to see if/where the connection is being lost.