My Mac switches to speaker after locking the screen
Yes, make sure that under System Preferences -> Sound that the default device (Headphones) is selected. After setting this, my Mac was remembering that I was using headphones after unlocking the screen.