Based on Maryamā€Ÿs example, if one was faced with an insurmountable tribulation, it is permissible to ask Allah to take their soul. There are two examples from the time of the Prophet salla allahu alayhe wasalam that illustrate this. It was narrated the Prophet asked Allah that if he was to test his slaves with a fitnah (a major test in their faith), to take his soul prior to it. Umar was also quoted as saying on one occasion, he wished his mother had not given birth to him.
This is a quote from "The life of Jesus" by Ahmad Musa Jibril

I wanted to see how other people take this into consideration. IslamQA says asking for death in tribulation is a characteristic of impatience and ingratitude and therefore incorrect.