You could try:
Guid cID = new Guid(ViewState["CatID"].ToString());
ViewState appears to return an object which can't be cast to a Guid. If you try the above, you should be able to easily create the Guid from the string representation of "CatID" in the ViewState.
Also, in reply to your comment below, why not try this instead of the <asp:HyperLink>
:
<a href='<%# ResolveClientUrl("~/SubCategories.aspx") %>?id=<%#Eval("CategoryId") %>'><%#Eval("CategoryName")%></a>