The valuation is almost completely unrelated to "Yahoo" the core business. Yahoo the publicly traded company owns ~$40 billion worth of marketable securities (Alibaba and Yahoo Japan mainly).
Imagine if you owned a convenience store that had a vault with $40 billion in gold bars inside. Your business would be worth $40 billion, despite being a convenience store.