While I don't know why and don't have time to investigate right now, the hook you've chosen is too late. Your code works if you use, for example, init
instead of after_setup_theme
.
In addition, as written, your code runs on every page load which is a bit profligate. There should be a way execute this only on plugin activation or perhaps on a change of theme-- something that reduces the frequency this executes. Perhaps best case is a button in the theme/plugin to "Populate Defaults". Once this runs once it is not needed anymore as the data is in the database.