Two pole breaker for 240v circuit loses one side
Almost certainly a bad breaker.   Square D Homeline is the cheaper model than the QO breakers, but you'll have to replace it with another Homeline breaker since the QO breakers won't fit in a homeline panel.
BTW, I noticed that you are running 10ga wire.  That isn't rated for 40 amps.  And to be running 40 amps to a pump, it must be a heck of a big pump.  What's it being used for? Commercial irrigation?
Also, it may be a loose connection someplace, like the wires themselves or the feed to the panel.