In short: it depends.
You are allowed to include screenshots of textbooks or lecture slides but they should not make up the majority of your uploads. They also should only be in your document for the purpose of annotating or criticizing them, and not in order to share the textbook or lecture slides content with others.
It's important that you're aware of our Community Guidelines for this, as it goes into more detail as to the specific nature of "Respecting intellectual property rights". Specifically:
"We encourage sharing as many high quality study notes and materials with each other as possible. Afterall, you never know what someone else might find helpful or inspiring. However, please make sure to respect other people's or party's intellectual property rights and only upload content that you have created yourself.
It is okay to include images that are already publicly available, for example from Google Image Search. You can also add screenshots from lecture slides and textbooks if the main purpose of including them is in order to "criticize" them. However, the main part of your uploaded materials should be created and owned by yourself."