Dear Rabbi Simon,
Should the mitzvah of prayer in a minyan be canceled at a time of danger of being in a dangerous place or being persecuted by non-Jewish authorities, for example, going to prison? This means a danger that may come true (and many people, not only Jews, take it seriously), but it may not happen either.
Thank you for your question.
It is difficult to provide a completely definitive answer without knowing further details, eg is it possible to curtail the prayers within acceptable parameters? Is the law capricious or legitimate, ie based on genuine and objective concerns? How severe is the danger? Does the danger affect only those who gather for prayer, or could their communal prayers actually come to endanger others as well? Are you asking whether the prayers must be cancelled, and one is not allowed to pray with a minyan, or simply whether one may be permitted to forgo communal prayer in the circumstances you describe.
Nevertheless, with the above considerations taken into account, I would be inclined to say that the answer is yes, there are grounds to cancel communal prayers to avoid the risk of imprisonment.
I hope this is helpful.
Rabbi Rashi Simon