What would cause a pedal to loosen from its spindle while riding?
Sounds like you'd lost the locknut, allowing the outside cone to back off slowly, then walk right out the end pushing the dust cap with it and freeing all the ball bearings.  Perhaps you didn't tighten the locknut against the conenut and they moved as a unit?  Mismatched balls can push on the cone too, specially if there's spalling or pitting developing already.
Another less-likely possibility is that the cone nut was too tight against the balls, and they manually unwound the cone nut as you rode.  However this would be a tight feeling, not a loose feeling.
Given the cone nut is lost, its going to be less work to find a pair of replacement pedals, grease the threads, and fit them to the correct cranks.  This will get you riding again.
You might choose to save the old pedal remains as spares, or recycle them in some way.