Hi
Apple advises that it can be normal for your iPhone to become warm when using it and also in other situations including when charging it, first setting it up, restoring from a backup and when apps re-index or re-analyse data (such as when Photos performs background tasks after a software update). The exterior acts as a cooling surface, transferring heat from inside the iPhone to cooler air outside.
Apple also notes that charging your iPhone when it is inside certain styles of case may generate excess heat, which can affect battery capacity. If you notice that your iPhone gets hot when you charge it, Apple advises that you should remove it from its case before charging.
Be sure to follow all of Apple's safety and handling guidelines, including those detailed here:
If you are concerned that your iPhone gets warmer than it should do, I suggest that you contact Apple Support (mail-in service may be available), make a Genius Bar reservation or visit an Apple Authorised Service Provider with a view to having your iPhone checked and, if recommended, serviced / replaced under warranty: