Railway Mania in England William Quinn et al. in their Boom and Bust (Cambridge University Press) describe the causes of the Railway stock market bust in 1840s England.

The outflow of gold due to problems with the harvest prompted the Bank of England to increase its interest rate from 2.5 to 3 per cent on 16 October and then to 3.5 per cent on 6 November. Some commentators have suggested that the decline in railway share prices was attributable to these rises in the Bank of England rate – the Bank was in essence pricking the bubble.

My question is, how could bad harvest season make the Central bank to increase in key rate? From the description, it seems that the anything but the decrease in economic activity was needed. Also, how the increase in the key rate could could have made a contribution to the declining prices? At least in theory.
how could bad harvest season make the Central bank to increase in key rate?

At the beginning of 1800s Britain still roughly $36\%$ of a employment and $33\%$ of British GDP was generated by agriculture (see Grigg 1992). Hence shock to agricultural output could easily lead to recession and have widespread economic effect.
Given what large role agriculture played in the Britain's economy I do not think it is surprising that central bank decided to act in some way. Hiking interest rate in such situation might seem strange with hindsight and living in current fractional reserve system, but that was part of what Keynes called the 'rules of the game'.  As explained by the oxford reference:

Under the ‘rules of the game’, countries losing gold were supposed to raise their interest rates and cut their money supply; countries gaining gold were supposed to cut interest rates and increase their money supply. These rules were intended to restore equilibrium in the balance of payments fairly quickly.

Fall in output (in this case agricultural output) would cause gold outflow because suddenly UK would loose production that was meant to be exported which would worsen its balance of trade. Moreover, under gold standard imports create gold outflow and exports gold inflow. So to play according to the 'rules of the game' the central bank had to hike interest rate.
Of course, doing this in our present fractional reserve system would make no sense and hence it feels very counterintuitive. However, under gold standard central bank cannot just let all gold flow out of country as that would lead to balance of payment imbalances as with gold standard all countries are implicitly under the same fixed exchange rate regime. This was also one of the reasons why eventually gold standard broke down and generally it is not very stable and resilient monetary regime (Eichengreen &amp; Temin, 2010).

Also, how the increase in the key rate could could have made a contribution to the declining prices?

Higher interest rate leads to decrease in prices because it incentivizes people to spend less and save more putting less pressure on prices.