"(I) Ain't got no pencils" is grammatical in that it meets the syntactic requirements of the grammar. It has a subject (implied), a verb (ain't got) and an object (no pencils). With regards to Standard English, though, it's considered unacceptable. "-n't got no" is a double negative, and "ain't" is non-standard usage, which isn't/ain't to say that speakers won't or don't use it. <I do. It's part of our living language>
"ain't got no" is another way of saying, haven't / hasn't (got) any.