Check for fault codes, I have had something similar on my Impreza and Glanza previously. Impreza turned out to be loose cam sensor so check yours is connected properly/ not broken (i.e a fault code). My Glanza did it with both air intake, and water temp sensors goosed (again check for fault codes on them or check continuity) Must add if the cam sensor is just loose you wont get a code. Maybe youve disturbed an already weak wire/connector on something.