I looked at both of those functions. They go to ContactManager, which registers names/ids from your contact list, kmail, messages in chat, and so on.
If a name or id is known, it's a simple lookup. If not, the ContactManager will do "/whois" with the name or number and enter the results in its database.
Turns out that get_player_id() was doing that, but get_player_name was not. Revision 20059 forces a /whois for get_player_name if the contact is not known.
I don't know why it sometimes returns a number for the name or the name for the id. I'll poke some more.