There is a trick when setting up a timer on your iPhone which automatically stops any playing music when the timer ends. To automatically stop music on iPhone, do as follows:
1. Open the Clock application on your iPhone (running at least iOS 8)
2. Go to the Timer tab
3. Specify when the timer must end using the Hour and Minutes options
4. Before hitting the Start, tap the When Timer Ends option, scroll all the way down and make sure to mark the Stop Playing option
5. Tap the Set button on the top right, followed by the Start button
6. Now, the timer starts and any playing music will be automatically stopped as soon as the timer reaches to the end point.
Tip: You may use this trick before sleeping by setting the iPhone to play some relaxing music for about 20 minutes and then stop automatically