Are "didn't know" and "hadn't known" grammatically interchangeable? Or is one better than the other?
This is probably a matter of semantics (meaning) rather than grammar (structure). See below.
"hadn't known" is the past perfect tense which implies that the "not knowing" ended before some other event (in the past).
"didn't know" does not necessarily imply such a relationship.
I didn't know how to do any of the homework questions.
I hadn't know that I would fall in love before she walked into the room.