The ID check isn't for age verification. Federal law requires IDs to be recorded* to enforce restrictions on the maximum quantity that an individual is permitted to purchase per month.
* Edit: Where the word "recorded" appears, this comment previously said "scanned and submitted to a central database". While most states use a central database, the comment reply below pointed out that this goes beyond the minimum that federal law requires.