There are a couple answers because their beaks are powerful tools that can be used in different ways. The tapping can be used to signal other birds in the area. Unlike people, they can’t talk, so the pecking is how they communicate!
They also use their beaks to chip away parts of dead trees. Once they chip away enough, they can make a cozy nest inside.
Woodpeckers also use their beaks to make holes in trees to find little bugs crawling around in the bark. Bugs are a very tasty meal for woodpeckers. Gross!!