Copyright law has specific exceptions for some types of uses of works associated with teaching.
17 U.S.C. § 110(1) permits the performance or display of legally licensed/purchased works, for strictly and directly pedagogical purposes relevant to the course, in face-to-face classes at nonprofit educational institutions.
17 U.S.C. § 110(2) (TEACH Act) permits some uses of copyrighted works in online classes, but only under certain circumstances. To determine if your intended use would qualify see CLEAR’s Copyright Guide.