Trump blew up standing DACA policy, saying he wanted congress to make a law because executive orders are apparently illegal when black presidents enact them. Dems and Republican immigration moderates took him at his word and tried to work something out. Trump yanked the rug at the last minute and threw in with hardliners, meaning there was no pressure for Ryan or McConnel to bend past their hardliners' comfort zone. So Senators disappointed by bad faith withheld support.
It's a simplification, but Trump's fuckwittery makes me feel quite justified in assigning him a good chunk of the blame for the shitdown.