GNU sed:
sed '/^#/,$!d;:1;/^\s*$/N;/\S/!b1;/^#/M!Q' file
/^#/,$!d - Cut off lines before the start of comments.
:1;/^\s*$/N;/\S/!b1 - If there are empty lines or only spaces, add to the buffer(pattern space).
/^#/M!Q' - if a line is encountered that does not start with a comment mark, exit the script (M - Anchors will be valid in a multiline buffer).