Mechanical theory of nonequilibrium coexistence and motility-induced phase separation