If you want the associated bpo ticket to be closed when the PR is merged, you have to add the commit message saying
"closes <bpo url>" 
(Note that we should document this: https://github.com/python/devguide/issues/502)


If you want the the associated GitHub Issue to be closed, it is similar, you have to add to the commit message or the PR description:
"closes <github pr url>" 
Documentation: https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword