The Trainspotting star, 60, plays prime minister Robert Sutherland in Sky’s political thriller, inspired by a fictional government's reaction to times of national crisis.
Conservative MP Sir David – a 69-year-old father-of-five – died after being stabbed multiple times at a constituency surgery in Essex last week.
Carlyle told Sky News: "The first thing to say is your thoughts and your prayers go to the family of that poor man. What a terrible, terrible, dreadful thing to have happened."
All six episodes of the second series, Cobra: Cyberwar, were due to be released on Friday 15 October, but Sky decided to temporarily pull the final three shows following Sir David's death due to sensitive content.
Carlyle went on: "What I should say obviously is that Cobra, it's a fictitious entertainment [show] and... some of it will reflect real-life events but it's not meant to do that.
"First and foremost it's there to entertain people, it's there to give people a little bit of insight into the workings of the [government's real-life] Cobra room. Hopefully it does that."
The first series of Cobra, which aired in January 2020, saw Sutherland's government attempting to manage the fall-out after a solar flare wiped out power – sparking panic and rioting.
The second season is centred around a huge cyberattack.
Carlyle said of the new series: "It's about the power of fake news and the destabilising effect it has on a democracy.
"And then overall, as the title suggests, there's a massive cyberattack launched upon the country's critical infrastructure and transport – our emergency communications and even nuclear facilities are attacked. So there's a lot going on."
Following news of Sir David's death the BBC made the decision to pull political panel show Have I Got News For You and crime scene comedy The Cleaner from TV schedules.
They were replaced with reruns of panel show Would I Lie to You and sitcom Miranda.
Watch: Robert Carlyle comments on the state of politics in Britain