This quote is an expression of he spiritual connection of the poet to all people and things. When he says he is as bad as the worst and as good as the best, he means that he contains within himself both the best and the worst, and that each is in its own way necessary. Or to put it another way, the person who can identify with the worst in people can also identify with the best.
Whitman's poetry is a poetry of inclusion. Whitman believed that God was part and parcel of everything, and that the low or debased were as holy as the "best" or most upright. The fact of existence proved the divinity of things. For this reason, Whitman rarely makes moral judgements.
Another way the quote can be understood is as a statement of the interrelated nature of "good" and "bad." Whitman saw plenty of "bad" things during his time working in hospitals during the Civil War, and it may be that this experience reinforced his appreciation that valor on the battlefield (the "best") leads to injury and death (the "worst").
Finally, Whitman could be speaking about his own moral makeup. He sees within himself the capability for the "best" and "worst."