This is a great question! It seems a bit weird to talk about cake. Saying that something is a piece of cake means that you are saying it is very, very easy.
For example, if you go back and try first grade math, you will think that it is a piece of cake. The reason that cake is used in the idiom rather than another type of food is simple – everyone loves dessert and cake!
Most people really like cake, and being able to eat it is very, very easy. Sometimes you don’t even need utensils; you can just nibble the slice until you are full. Plus, cake is a sweet dessert meanings that it is something that is just more universally liked. If you changed it to pork, for example, there would be a lot of people who do not eat pork for one reason or another.
Actually, cake is used in a couple of different idioms in English. Some examples of this include:
- You can’t have your cake and eat it too (You can’t have everything; you have to either choose one or the other)
- To take the cake (To be the most extreme example of something – whether good or bad – in a group)
- To be icing on the cake (To be an added bonus that makes something that was already good, even better)
- To be a cakewalk (To be very easy to do)
- To sell like hot cakes (The hot cakes here typically refers to pancakes, but the idiom means that something sells very, very fast)
- Pie in the sky (Something that looks really nice and that would probably be really great, but is actually unrealistic)
- Slice of the cake (A share or portion of something)
- Cakes and ale (A good time)
To add to the answer above: another similar expression (with the same meaning) is easy as pie.