First, always keep in mind the target audience. Fanfiction is often read by a diverse group of people, including younger fans. Second, focus on the positive aspects of the characters and the story world. Instead of creating such inappropriate scenarios, think about how to develop the characters in a more positive and interesting way. For example, exploring their relationships, their growth, or their adventures.
Avoiding this type of inappropriate content starts with having a good understanding of the boundaries of good taste. Don't write things that are overly sexual or disrespectful to the characters. Try to base your fanfiction on the positive elements of the original work. For instance, if the original story has themes of friendship and loyalty, expand on those. Also, get feedback from other writers or readers who have a good sense of what is appropriate in the fanfiction world. This can help you stay on the right track and avoid creating content that might be offensive or inappropriate.