TikTok has secured the rights to recordings from thousands of artists, including Beyoncé and Travis Scott, under a new deal with Sony Music Entertainment that will deepen ties between the world’s second-largest record-label group and the popular video app.