All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad, sallallahu ‘alayhi wa sallam, is His slave and Messenger.
Scholars held different views on writing fictional stories that are void of forbidden speech, promotion of what is prohibited, disrespect for the religion of Islam or Muslims, or showing reverence to falsehood, dissoluteness, and sins or the people who are given to them. Some scholars held that it is disliked, while others believed that the most likely correct view in this regard is that it is permissible if the objective for writing them is noble, such as teaching knowledge, promoting a virtue, urging people to embrace courage, giving good examples and lessons, or if they include social and moral benefits, whether the stories are narrated by people, animals, or inanimate objects. Writers and poets have been following this practice in their writings for long, such as the Maqaamaat (an Arabic literary genre) written by Al-Hareeri, who used a fictional character to address a specific issue, and it was well received by all, scholars and laymen.
The Muslim poets composed their poetry during the lifetime of the Prophet, sallallahu ‘alayhi wa sallam, and used to open their poems with fictional stories, like the well-known poem "Baanat Su‘aad", in praise of the Prophet, sallallahu ‘alayhi wa sallam, and he did not forbid them, nor did the Companions, although such openings related fictional stories about abandonment and separation which the poet might not have experienced in the first place.
Ibn Al-Muqaffa‘ wrote a fable entitled Kaleelah wa Dimnah, narrated by animals, and it was well-received by the public and scholars.
So the preponderant view is that it is permissible to write this kind of fictional stories, contrary to what is the case if the stories contain Shariah violations, praise of falsehood, or impermissible images of women. In this case, such stories are deemed prohibited.
Allah knows best.