Power supply problem with L293D
Look at the data sheet for the 7805 and you'll find it needs a 0.1uF capacitor and a 0.33uF capacitor (or larger). Both caps should be non-electrolytic (for best performance) but, adding an electrolytic in parallel with the caps I've said won't be a big deal.

If this now works on both batteries then it's a fair assumption that the wiring to the 12V battery may be too long or the ability of the 12V battery to act as a decent capacitor was impaired.

Link