Why can't I create a public game mode class in my HUD class?

It looks like you need to forward declare the AMyProjectGameMode class in your header. Try adding a line

class AMyProjectGameMode;

before your HUD class definition.

I am getting errors when I am trying to create a public variable of my game mode in my HUD class.

CustomHUD.h

AMyProjectGameMode* GameMode;

1>d:\ue4\new folder\myproject\source\myproject\MyProjectHUD.h(14): error C2143: syntax error : missing ‘;’ before ‘*’
1>d:\ue4\new folder\myproject\source\myproject\MyProjectHUD.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int