why does gas have pressure?

Because it consists of moving molecules that transport momentum and collide with walls of containers. Each collision imparts an impulse.