The ukulele developed in Hawaii in the first decade of the 20th Century. They grew out of instruments brought over from Portugal (the machete and the braguinha). Both of these instruments were guitar-like in shape (but smaller) so the ukulele began its life in that shape.
The pineapple shape of ukulele was invented by Samuel Kamaka and it was patented in 1927. Kamaka was at the forefront of the second generation of Hawaiian ukulele makers – he had apprenticed under Leonardo Nunes (one of the original ukulele makers) before leaving to set up his own company – which is still running today – in 1916.
You can even view the original patent on Google. The original didn’t just go with the oval pineapple shape. It also have a pineapple design painted on the back and front.
With the patent expiring in 1942, many other companies have since picked up the pineapple shape and today it is very popular with it being produced by companies such as Kala, Lanikai and Pono.