I want to know what was the motivation/intuition behind weierstrass function? I know that it came as an example of a function that is continuous everywhere but differentiable nowhere.But how did the idea of such an unusual construction came?
 A: I'm writing as a community wiki, since it's been a long time since I've looked at this stuff. Here's the way I understand it:
The aim is to create a function that is not differentiable anywhere, without sacrificing continuity at even a single point. We are familiar with examples like $|x|$ of functions that are continuous everywhere, but that fail to be differentiable at a single point. Such functions have a noticable "corner" (known as a "cusp") where the function fails to have a (unique) tangent.
There is another way in which a function can fail to have a derivative: if it has a vertical tangent. For example, $\sqrt[3]{x}$ has no derivative at $0$.
So, it would be good if we found a continuous function where every point fell into one of these two categories.
Ignoring the trigonometric functions for now, we can build a continuous function with as many cusps as we like (finitely many) by summing various translates of the absolute value function. For example, $|x| + |x - 1|$ fails to be differentiable at $x = 0$ and $x = 1$ at the same time.
We could even sum countably many such functions and obtain cusps at a countable set of points, provided some adjustments are made to preserve convergence and continuity. Provided the functions are bounded and properly scaled, we should get uniform convergence of the partial sums, which will guarantee continuity of the resulting function. The resulting function should hopefully have countably many cusps.
In fact, you can distribute these cusps densely amongst the real numbers! Since $\Bbb{R}$ is separable, we could put cusps at a dense, countable subset of $\Bbb{R}$.
It's not clear if you can put cusps at any more than a dense countable set (or what that would even mean), but if you do things right, the sum of the slopes between the cusps should hopefully tend to $\infty$ or $-\infty$. In other words, the points between the cusps fall into the other category of non-differentiable points in a continuous function: points with vertical tangents.
This is what happens for the Weierstrass functions, and various other functions that achieve the same end: you get cusps countably and densely, while the points in between have slopes that approach $\pm \infty$.
So how do trigonometric functions give us cusps? Well, trigonometric functions can reproduce any continuous function on a compact interval, using Fourier series. We can make cusps by summing various sine curves, with rapidly increasing periods (so that their maxima and minima become sharper), which share a common maximum or minimum. The derivatives conspire to change so rapidly from positive to negative that, when summed, a cusp is formed at the given point.
By controlling how fast the periods increase, and how the amplitude decreases, you can sum trigonometric functions in such a way that cusps form densely and self-similarly, and the points in between have tangents with divergent slopes.
Why did Weierstrass use smooth functions to make a non-differentiable continuous function? You'd have to ask him. My guess is that his understanding of Fourier series lead him to think in terms of trigonometric polynomials.
A: This biography of Weierstrass suggests that it might have been inspired by a comment of Riemann, together with Weierstrass' concern for rigour:

In 1872 his emphasis on rigour led him to discover a function that, although continuous, had no derivative at any point. Analysts who depended heavily upon intuition for their discoveries were rather dismayed at this counter-intuitive function. Riemann had suggested in 1861 that such a function could be found, but his example failed to be non-differentiable at all points.

