The correct and direct answer to this question is in snailboat's comment:
"He doesn't know to swim" is a grammatical and meaningful sentence,
but it does not mean the same thing and it is significantly less
common
As stated in fumble_fingers's answer, "He doesn't know to swim" is equivalent in meaning to "He doesn't know he should swim." Yes, it is a grammatically valid sentence.
However, it is not common. The [he/she knows]+[infinitive]
construction is fairly rare and I suspect it might be more common in BrE than AmE.[1] This is compounded by the use in the negative ("He doesn't know to swim"), which would be even less likely to come up -- maybe if someone is on the deck of a sinking ship, but she doesn't know it is sinking? I would much more frequently say "She doesn't know she should swim" to achieve that meaning.
So I would also hazard a guess that the creator of the website that OP references is perhaps also an AmE speaker, and it didn't occur to him or her that "he doesn't know to swim" is a "correct" sentence in some circumstances because it is so rare.
Also, the underlying meaning "Do you have the ability to swim" also comes up much more frequently (dozens of times in my life, perhaps more), such that "know how to swim" is almost an idiomatic construction due to its frequency of use.
By contrast, a context for the meaning "Do you know it is appropriate and needful for you to swim now?" comes up . . . almost never, only on sinking ships and similar swimming-needful crises. So the language learning site was just trying to illustrate the most common scenario.
If you're an ELL student, it's much more likely that you want to know if your friend can swim, so you can invite him to a pool party, rather than whether he should swim.
[1] Fumblefingers is in the UK. Both FF's linked book examples are US authors, so I guess that doesn't help me, but we do have me, snailboat, and GalacticCowboy (all AmE speakers) saying it seems like an unusual or uncommon construction.