Yes, it's confusing. "-다니" is a sentence connecting expression that has meaning of "Because I heard ~~ or To hear that ~" .
Your focus sentence is "하필이면 그런 남자와 결혼을 하다니!" It can be translated like "I am feel ~~~ because you are getting married, how come, with that kind of man!" So in this Korean sentence, "I am feel ~~~" part is actually omitted.
"-다니" is often used with exclamation mark or can be used in sentence ending without completing the sentence fully because of speaker is emotional. In other words, the full sentence structure could be "---- 다니 나는 --게 느낀다 (feel).
How about " ~ 다니까" ? "- 다니" can be used in sentence ending. Remember, it can be used in sentence ending. But "까" has clear meaning of "because" in Korean. So you should put a logical reason before "까" and a result after "까". So after "다니까" you need to complete your sentence with a result expression based on your reason before "다니까".
Let's look at example sentences. These two sentences are all correct and proper.
"네가 1등을 했다니까 너무 기쁘다!" (I am so happy to hear that you got the 1st place!)
"네가 1등을 했다니! (I am ~~ to hear that you've got the 1st place!)
I hope this helps!
Thanks,
Mina Yeon