`ob ... gilt` is a relative subordinate clause. It relates to the surrounding sentence: it further explains which `Frage` the rest of the sentence refers to.

As such, it needs to be surrounded by commas. See [Duden D118][duden] and §74 (on page 81) of the [official rules (released 2018, PDF)][rechtschreibrat] ([online version][grammis]) based on the 2016 recommendations of the council for german spelling. Both sources are in german.

---

Subordinate clauses can be identified easily: if you drop out everything between the commas, it should still read as a valid sentence (that may provide less information though). `Die Frage darf man nur stellen, wenn ...` is valid, hence you need commas when inserting a subordinate clause.

Another example: `Die Frage darf man, selbst als Geschäftsführer, nur stellen, wenn ...` This subordinate clause indicates that even a CEO may only ask this question, when ... This construct sort of indicates that the sentence is about a very special or tricky question (which not even a CEO may simply ask), even though the subordinate clause is not placed next to `Frage`.

 [duden]: https://www.duden.de/sprachwissen/rechtschreibregeln/komma#D118
 [rechtschreibrat]: https://www.rechtschreibrat.com/DOX/rfdr_Regeln_2016_redigiert_2018.pdf
 [grammis]: https://grammis.ids-mannheim.de/rechtschreibung/6201#par74