Although not the only possible cause, the battery in Mac notebooks can affect trackpad function if the battery fails and begins to swell. Swelling progresses rapidly and exerts enough force to damage or destroy your computer, so I would not delay in taking your MBP to Apple as soon as possible for evaluation.
I don't recommend your opening the case, but a simple non-invasive test often picks up early evidence of swelling. Place the computer on a known flat surface (quartz or stone countertops are remarkably flat) and see if the computer rocks on three feet instead of resting solidly on four. That trumpets a bad battery and demands immediate service.
Another indication of a swelling battery is the fit of the case bottom plate to the case chassis. Any gapping in that otherwise tight fit is a big red flag.
Less dire causes may be corrected with an SMC reset:
How to reset the SMC of your Mac - Apple Support
If your computer does not rock or show gaps in the case, try the reset.