I created two documents with same pixel dimensions (1280x768).
Document 1: 72ppi
Document 2: 300ppi
When I saved both in
.png, they have the same size on the hard disk. Why do I need PPI? Why can't I just use pixels?
Because in print, you need other dimensions as well as the information of the density to be able to judge if the result will print ok. Yes, as long as you stick to web you can mostly ignore it. But in print it makes all the difference.
Answering the specific points in the question:
...two documents with same pixel dimensions (1280x768)...
When I saved both in .png, they have the same size on the hard disk
Those aren't normal low and high res variants - what you have there, is two images that are identical, except that the low PPI thinks it's going to spread those 1280x768 pixels thinly across a large area, while the high PPI one thinks it's going to concentrate those 1280x768 pixels in a high quality print on a small area. But the important stuff - the data - is the same.
I'm guessing what happened here is, you changed the resolution in [something like] Photoshop leaving [something like] the 'Resample Image' box unchecked.
This means your image didn't actually change - it just changed how many inches of paper it thinks it can stretch those pixels over.
If you go back to the 300ppi original and scale it down again with "resample image" (or equivalent) checked, it should give you the more lightweight low-res file you expected.
If you'd had the 'Resample image' box or equivalent checked when you changed the resolution down from 300 to 72 to make the low-res image, it would have kept the size in inches or centimeters the same, and simplified the image so that each inch had only 72 pixels instead of 300. For example, If you had a business card design, 3.5 inches by 2 inches, 300 PPI, and you did this, it would still be a 3.5 inch by 2 inch business card, but it would have fewer pixels. It would be a smaller file and would print lower quality, on paper of the same size.
If the 'Resample image' box was unchecked, it would keep the 1250 by 600 pixels, and just calculate how many inches this could cover at 72 pixels per inch. It would be exactly the same image, just thinking it could print bigger because it thinks you're less fussy about print quality, so it thinks it can stretch its pixels further.
There is an awesome article on Wikipedia about this subject. https://en.m.wikipedia.org/wiki/Pixel_density But, as it has been said before, if your document is to be printed, choose 300ppi, but for the web and game development, 72ppi is suitable.
ppi just means 'when you display it, how many pixels are you cramming into an inch of real world space'. Higher ppi (density) means smaller area to stretch your pixels across.
As computer screens have a fixed set of pixels, based on your monitor, it will always display the image at the same size (1 pixel = 1 pixel) regardless of how big or small the ppi (density) is.
Typically screen is considered 72ppi (or 96ppi), but it really depends on your monitor, so ppi is only really relevant to print.
ppi is short form of pixel per inch, also called as dpi, dot per inch. Changing resolution, in this case 72 ppi or 300 ppi will change only document size. Document size is changed when we need some changes in image size going for printing. Total number of pixels remains unchanged and hence despite change in document size image size remains same. It is to noted that image size and document size are two different things.