The egg yolk contains molecules (called lecithin) that stick to both water and oil, which creates an emulsion. This is what causes mayonnaise to thicken.