The first couple of paragraphs say that y must be a condensed distance matrix, but the Parameters section says that y is optionally a data array. In practice the function does different things depending on the shape of y: if it appears 1d then it is treated as a condensed distance matrix, otherwise if it is 2d then it is treated as a data matrix (not as a compressed or uncompressed distance matrix). If it is not 1d or 2d then it falls off the if/elif and tries to return something that doesn't exist.
Here's the MATLAB function that hierarchy.linkage appears to try to clone:
Duplicate? See #2614
closing as duplicate