The "stair-step" pattern visible in the first image is characteristic of the the Hubble's Wide Field and Planetary Camera 2 (WFPC2). This pattern is created by the arrangement of the four CCD chips. This image shows how the three larger "wide field" chips and the smaller, single "planetary camera" chip are arranged to create the pattern.
The bottom picture appears to be a slice of the original Hubble Deep Field, which was also captured with WFPC2.
So the answer, for these two images, is that the shape of the image is an artifact of image capture.
However, in general, finished images such as these could take up any arbitrary shape. Many of the modern images contain data from multiple views, multiple cameras, even multiple telescopes all drizzled together using specialized photo processing software.