Let’s go through a few things that take up more space in an iPhone than the S8:
The actual SoC is bigger. It uses more silicon than competing snapdragon processors.
Taptic Engine in newer phones (6S and up, made bigger in the 7/8/X)
https://www.androidauthority.com/apple-a10-fusion-chip-performance-723918/
People always assume the problem comes in depth and forget there are other dimensions they need to take into account.
That’s the thing. Every design needs to balance the requirements from competing groups. The design team has an idea of how the phone will look. SW ideally wants more processing capabilities and also longer battery life. HW needs to stuff everything to fit into design dimensions. The final design will have all kinds of trade offs. Apple has decided that they can work with smaller battery capacities.