We were in Denmark a few years ago and absolutely loved it. With 5 full days, I would stay in Copenhagen the whole time as a base and then take day trips. There's a lot to do in Copenhagen itself of course. For castles, Rosenborg, Amalienborg, and Christiansborg. We thought the walk up the Rundetaarn was need for the views. The Little Mermaid statute is, in my opinion, not worth going out of your way for. Definitely would recommend a canal boat tour. We walked through Christiania - not everyone's thing, but it was a beautiful day and we enjoyed it, especially once we got past Pusher Street. There was also a really cool food hall called Copenhagen Street Food that was right along one of the canals with lots of outdoor seating that we loved. We were there at a time Tivoli was closed, but if it were open we definitely would have gone. There is of course more to do here than just these suggestions, we really liked Copenhagen.
As for day trips: (1) Roskilde is great (UNESCO World Heritage Site Cathedral where Danish monarchy are buried and the awesome Viking Ship Museum), and it is only like 25 minutes from Copenhagen; (2) Helsignor (I think this was just about an hour north of Copenhagen - Kronborg Museum, the excellent maritime museum, and on the way back to Copenhagen, a stop at the Louisiana Museum of Modern Art); and (3) Hillerod (Frederiksborg Castle and cute town).
If you are really interested in Hans Christian Andersen, you could do a day trip to Odense (where he was born). We stayed there for two nights and really enjoyed it, a much smaller town feel than Copenhagen. If I recall correctly, the train from Copenhagen to Odense was around 1.5 or 2 hours each way - a bit long, but doable for a day trip. In addition to the HC Andersen museum (very good) and his home (just ok), we really enjoyed the open air Funen Village Museum (Den Fynske Landsby, a bit south of town), and the ferry in and around the Munke Mose park).
Legoland is all the way in Billund and personally I don't think you have the time for it.