I will tell you my story. Bear with me - it makes a point. Long, long before I met my current husband, I loved another. I grew up with him, knew his family from church, and was friends with his sister. We grew up and he moved away, but when he was diagnosed with a terminal illness, he moved back to our hometown and eventually we got back in touch and spent friendly time together. He was not expected to live long, but he did... and after years of being friends, I heard God speak "just love him." I obeyed, and our love grew deep.
He initially had some issues like you do - he did not want to put me through loving him only to lose him, but it did not matter. The love was there, and there was no stopping it. People knew we were very close friends, but only a handful knew about the love, the spiritual connection, the incredible bond we shared, and the relationship was godly (we did not become sexual with each other). We held hands, kissed each other goodnight, played footsies, walked arm in arm, but we honoured God in our relationship. We talked of marriage, and wanted to spend our lives together, no matter how long one of those lives would be - after all, I could have married him, walked outside the next day and been hit by a car. There are no guarantees.
Around the same time we started talking about marriage, he came out of remission and got sick very quickly. He became bedridden before long, and I went to visit him often...at one point, his sister was there, and he "introduced us" as husband and wife...it was his way of making our relationship public. Others in his family already knew, although I did not find out until the funeral.
I would have married him if he wanted to before he died, and not for any legal reasons. I would have done it to publicly declare my love for him, to privately declare my love for him, to fulfill his dreams, to spend even one night with him even if it were never to be consummated, but just to have and to hold even for one night. I was prepared to make a vow till death do us part, and even did that with him in private on our last date out.... and it had a meaning attached to it that far more real than for two healthy people standing in front of a marriage officiant surrounded by friends and family.
All that is no disrespect to my current husband, who I love with all my heart. My beloved from all those years ago had a significant influence on my entire life for the next decade as I grieved. Mostly, though, if it were not for him, I would not have been so choosy about dating and marriage with my current husband. He was good for me at that time in my life, and I honour his memory. God knew that he needed to die knowing he was well loved, and God knew that I needed to know what mature love was, so I could use that knowledge in my future search for a spouse.
When God first told me "just love him," I argued with God, "but he's dying!" And God said "I promise I will make it worth it." And he did. The many years of grief were a drop in the bucket compared to the few years of amazing love!
I don't know why others marry on the deathbed, but I know why I would have done it...