It was random because Nucky was told "you can't be half a gangster", and he succeeded doing exactly that. He outsmarted everyone on the show, came out on top, and after the fact shot arguably the second most important character on the show. For what exactly? He'd already won
his way.
It seemed seemed kinda cheesy and tacked on. Like the writers wanted to end the season with a

moment and threw all logic out the window.
Then to make matters worse he commits the murder in front of Eli, who already betrayed him once, and is facing jail time Nucky asked him to take. So what's to stop him from snitching to avoid his sentence? Nucky ain't smart enough to think of that?
shyt made no sense at all.
And it's not as if I'm the only person. Fans went nuts talking about "fukk this show, no Jimmy no show!" after that ep. So nah, you can't kill off important characters just for the hell of it.