The conventional wisdom is that writers, authors, musicians, rappers, etc. should only undertake subject matter which they know. However, this is not necessarily true.
Nobel laureate Toni Morrison, author of the masterpiece Beloved and other works, disagrees with this advice. She believes writers should write about what they don't know.
It all depends on the writer. One of the greatest writers and literary geniuses of all time, William Shakespeare, was not afraid to write about what he did not know. He did not know from personal experience what is what like to be an Italian, a Jew, a woman, a Black man, etc. However, he brilliantly made such characters relatable to his readers.
The bottom line is that writers should write what they want to write about. With enough imagination, they can have great success and highly believable characters.