If yes, is there any simple solution to get palette from any bmp/jpg/png picture?
Not from
any, only from those that, on loading, resolve to a [pf4bit,pf8bit] image; any other won't have a palette to get. And I'm not even sure a jpeg can be a 4 or 8 bpp image.
For any other you'll have to build the palette yourself from the colors in the image (e.g. by dithering) and transform the bitmap.
It was "constructed" because in the Windows 3.x times the RAM was expensive and Windows was not able to operate on bigger amounts of RAM.
Not quite. It was used because that's what the underlying hardware (EGA/VGA 16/256 colors) used; and the hardware itself used it because it's the easiest solution to allow those no. of colors with the less fuss (and yes, the less memory).
Also, it's not a "Windows only" thing; high-end *nix workstations, the AmigaOS, and most other systems of that era used them too (each one in its own incompatible way, of course
). And conversely, you
could have a Windows 3 install working on 32K/64K/16M colors: you just needed a driver (most times from the manufacturer of the card) and a capable card+monitor combo.