This slang term for 'bad luck!' is British in origin and is now becoming rather archaic even there, although it is still used. It dates from the early 19th century and was used then just as a general indication of unsatisfactoriness. This piece, taken from a play called The Tiger at Large, which was printed in a collection of plays called The Acting National Drama, edited by Benjamin Webster, 1837, is the earliest citation I've come across:
Jem. His wages was too low. Don't you think a pound a month, and find one's self is hard cheese?
Hard cheese has, of course, got a literal meaning - cheese which is old, dried up and considered indigestible. That opinion was expressed in A Cyclopaedia of Practical Receipts, 1845:
Beer and porter should be particularly avoided. Hard cheese, unripe fruit, and especially beans, are also objectionable.
(Note: Receipts are what we now call recipes.)
The figurative meaning of 'hard cheese' clearly derives as an allusion to an unwelcome and indigestible course of events.