Lego had a patent on the design of the bricks 50 years ago - but failed to get a trademark on the shape of the bricks.
Apple got a design patent on the general shape of the iPad. Design patents are a convenient way to get around the fact that trademarks offer much less protection than patents and are generally assessed rather more sensibly.
My point is: even if they'd secured a trademark on the shape of the bricks, if that trademark covered functional aspects of that shape, the protections would not apply. Lego could attempt to enforce them, but a competent defence and court would reject them.
Apple got a design patent on the general shape of the iPad. Design patents are a convenient way to get around the fact that trademarks offer much less protection than patents and are generally assessed rather more sensibly.