This poem sounds like blowing up a balloon and then letting it drift slowly away. The first four lines are four big puffs of air. Each line is meant to be spoken in one breath, and each breath begins with the same sound, "When." You'll notice that these lines get progressively longer, just like how you have to blow harder as a balloon starts to fill up and starts to show resistance to more air. In the poem, the resistance takes the form of more and more repetition. Line two contains one short list (proofs and figures); line three contains two longer lists ("the charts and the diagrams," "to add, divide, and measure"); and line four summarizes and expands on the last three lines with such unnecessary details as "lectured…in the lecture-room." Through these increasingly long and cluttered lines, Whitman uses sound to express how intolerable the lecture has become. Careful! The speaker's gonna pop!
But, no, he decides to leave the lecture before that happens. In the fifth line, the speaker feels "tired and sick," just as you might after inflating a really big balloon or, ahem, reading some long free verse lines. Our poetry balloon is now full, and ready to "rise" and "glide" just like the speaker out of the room. So you'll notice that the last four lines are much smoother, gentler, and of more even length. The cluttered repetition turns into harmonious alliteration ("mystical moist" and "time to time"). The end of the poem brings the focus fully upward, to the sky and specifically the "stars," so our balloon theory is vindicated! (Sort of.)
We shouldn't be surprised that the meaning of the poem seems to track the sound so closely: that's what poetry does.