Harrisburg-based Mid Penn Bancorp and William Penn Bancorporation have entered into an agreement and plan of merger.