I expected the first one not to work since its a sort of legacy address.
Both are SegWit addresses. A legacy address starts with 1.
Am I missing something or does this function simply not work? It seems Electrum can do it just fine.
This function does not work. A standard of signing messages is currently
being worked on. Only Electrum is able to verify its messages signed using SegWit addresses. Either import your private key for that address into Electrum and inform the other party that they will be able to verify your message only using Electrum or use a legacy address instead.