Good morning Dale, Sara, Rat2, Joey
Yep, on my iPhone the Apple included Health app automatically tracks steps, flights of stairs climbed, calories burned, running distances and much more.
An iPhone doesn't need to be unlocked to gather data. When an iPhone is locked it's not off, it is in battery saving mode. We can still receive phone calls, texts and alerts while our iPhone's are locked. So an iPhone is awake, if you will, it just has it's eyes closed.
Here's the info on how to setup and use the Health app.
See your health and fitness information.
support.apple.com
FWIW...... the Health app will even tell you your Resting Energy!
Joey the Rally app integrates with the Health app to collect activity data. The info is on the App Store.