Without بِ, خبرُ مَا is accusative. When بِ enters, the same predicate remains the predicate of مَا but appears in the genitive form because it follows a preposition.
Structure
Predicate
Visible case
مَا الْوَلَدُ مُجْتَهِدًا
مُجْتَهِدًا
accusative
مَا الْوَلَدُ بِمُجْتَهِدٍ
بِمُجْتَهِدٍ
genitive after بِ
مَا هُمْ بِمُؤْمِنِينَ
بِمُؤْمِنِينَ
genitive plural form