mid-14c., crustade, "meat or fruit pie, any dish baked in a crust" from Anglo-French croustade (Modern French coutarde), from Old Provençal croustado "fruit tart," literally "something covered with crust," from crosta "crust," from Latin crusta "rind, crust, shell, bark" (from PIE root *kreus- "to begin to freeze, form a crust").
In Middle English also crustard, custade, etc. Meaning shifted c. 1600 to "compound of eggs and milk, sweetened and baked or boiled." The spelling change (by mid-15c.) is perhaps by influence of mustard. OED notes that custard-pie (by 1825) was "commonly used as a missile in broad comedy."