The most powerful artistic portrayals of anything come from people who have personally experienced those things – and there are portrayals that fail because the writer lacks the life experience. So it makes sense to advise people to stick to what they know.
Then again, many of us who enjoy writing fiction (or acting, or what have you) do so because we want to be not ourselves for a while. To play pretend. The impulse to create is a desire to transcend.
Even if we actually are explicitly looking to tell a personally experienced truth, the objective outward facts may obscure the essence. We may create to present a story with altered outer trappings so that the core can be seen.
Anything we create is a reflection of us, infused as it is with the extent/limits of our knowledge, our emotional state at the time, and the general sense of how our minds work. Anything we make embodies us, whether or not this is an explicit goal.
I don’t think any of us can help but write what we know.