The set of invertible elements in a unital Banach algebra is open (and nonempty), so its complement cannot be dense. Also, the closure of an ideal is an ideal. If X is not dense then its closure is not the whole of A. Therefore, if X is maximal then its closure must be X itself. Thus X (the kernel of f) is a closed ideal, and that implies that f is continuous.