Initialization is Critical to Whether Transformers Fit Composite Functions by Reasoning or Memorizing