Consistent subsectors of maximal supergravity and wrapped M5-branes