Elon Musk’s artificial intelligence chatbot Grok said “lapses in safeguards” led to the generation of sexualized images of minors that it posted to social media site X.