Why is "连忙" wrong in the following sentence?
连忙 and 赶忙 cannot be used in the imperative, although 立刻, 马上 (and also 赶快 and 赶紧) can.

Technically, 连忙, 赶忙 denote something that happens fast (now), while 立刻, 马上 denote something that is about to happen (soon).

See 连忙 as present tense, and 马上 as the future tense, if you will. Imperatives then belong to future actions.